 ///
 /// @file    virtualdestructor.cc
 /// @author  lemon(haohb13@gmail.com)
 /// @date    2016-03-15 11:37:50
 ///
 
#include <iostream>
using std::cout;
using std::endl;

class Base
{
public:
	Base()
	: _pData(new char[64])
	{
		cout << "Base()" << endl;
	}
	virtual void display()
	{
	
	}

	virtual ~Base()
	{
		cout << "~Base()" << endl;
		delete [] _pData;
	}
private:
	char * _pData;
};


class Child : public Base
{
public:
	Child()
	: Base()
	, _pCData(new char[64])
	{
		cout << "Child()" << endl;
	}

	void display()
	{
	
	}

	~Child()
	{
		cout << "~Child()" << endl;
		delete [] _pCData;
	}
private:
	char * _pCData;
};


int main(void)
{
	Base * pBase = new Child;
	delete pBase;//如果对基类的析构函数不加virtual
				 //此时，进行对象的销毁时，不会执行
				 //派生类的析构函数,就会造成内存泄露

	return 0;
}
